package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitorInterface;

public class BLOQUEFactory extends AbstractTokenVisitorFactory {

	private static BLOQUEFactory INSTANCE;
	
	private BLOQUE1Factory bloque1Factory;
	private BLOQUE2Factory bloque2Factory;

	
	public static BLOQUEFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new BLOQUEFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			bloque1Factory = BLOQUE1Factory.getInstance();
			bloque2Factory = BLOQUE2Factory.getInstance();
		}
	};
	
	private BLOQUEFactory() throws Exception {

	}
	
	@Override
	public TokenVisitorInterface makeChainedVisitor(
			final TokenVisitorInterface siguiente) throws Exception {
		initializer.init();

		return bloque1Factory.makeChainedVisitor(bloque2Factory.makeChainedVisitor(siguiente));
	
	}
	@Override
	public TokenVisitorInterface makeVisitor() throws Exception {
		initializer.init();

		return bloque1Factory.makeChainedVisitor(bloque2Factory.makeVisitor());
	}
	
	
}
